package com.hotelvip.controller;

import com.hotelvip.common.utils.JSONResult;
import com.hotelvip.dto.ReplaceVitemDTO;
import com.hotelvip.dto.TransferVitemDTO;
import com.hotelvip.entity.Item;
import com.hotelvip.service.ItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品 模块
 * @author Lzh
 * @date 2020/12/16 11:21
 */
@RestController
@RequestMapping("/item")
@Api(basePath = "/item",tags = "商品模块")
public class ItemController {
    @Autowired
    private ItemService itemService;

    @ApiOperation(value = "新增商品",httpMethod = "POST")
    @PostMapping("/saveItem")
    public JSONResult saveItem(@RequestBody Item item){
//        Long[] tIds = item.getTIds();
        itemService.saveItem(item);
        return JSONResult.ok("商品添加成功");
    }

    @ApiOperation(value = "根据id查找商品与可置换商品",httpMethod = "GET")
    @GetMapping("/findItemAndTurnItemById/{itemId}")
    public JSONResult findItemAndTurnItemById(@PathVariable("itemId")Long itemId){

        return JSONResult.ok(itemService.findItemAndTurnItemById(itemId));
    }

    @ApiOperation(value = "根据id查商品",httpMethod = "GET")
    @GetMapping("/findItemById/{itemId}")
    public JSONResult findItemById(@PathVariable("itemId") Long itemId){
        return JSONResult.ok(itemService.findItemById(itemId));
    }

    @ApiOperation(value = "查询商品列表分页",httpMethod = "GET")
    @GetMapping("/findAllItems/{current}/{size}")
    public JSONResult findAllItem(
            @ApiParam(value = "当前页码",required = true) @PathVariable("current") Integer current,
            @ApiParam(value = "每页条数",required = true) @PathVariable("size") Long size) {
        return JSONResult.ok(itemService.findAllItems(current,size));
    }

    @ApiOperation(value = "按照id商品信息修改",httpMethod = "PUT")
    @PutMapping("/updateItemById")
    public JSONResult updateItemById(@RequestBody Item item){
        itemService.updateItemById(item);
        return JSONResult.ok("修改成功");
    }
    @ApiOperation(value = "根据id删除删商品",httpMethod = "DELETE")
    @DeleteMapping("/deleteItemByIds")
    public JSONResult deleteItemByIds(Long... id){
        itemService.deleteItemByIds(id);
        return JSONResult.ok("删除成功");
    }
    @ApiOperation(value = "商品转让",httpMethod = "POST")
    @PostMapping("/transferVItem")
    public JSONResult transferVItem(@RequestBody TransferVitemDTO transferVitemDTO){
        itemService.transferVItem(transferVitemDTO);
        return JSONResult.ok("转让成功");
    }
    @ApiOperation(value = "商品模糊搜索",httpMethod = "GET")
    @GetMapping("/getItemByKey/{key}")
    public JSONResult getItemByKey(@PathVariable("key") String key){
        List<Item> items = itemService.getItemByKey(key);
        return JSONResult.ok(items);
    }
    @ApiOperation(value = "商品置换",httpMethod = "POST")
    @PostMapping("/replaceVitem")
    public JSONResult replaceVitem(@RequestBody ReplaceVitemDTO ReplaceVitemDTO){
        itemService.replaceVitem(ReplaceVitemDTO);
        return JSONResult.ok("置换成功");
    }




}
